const token = '123abc-456abc-789abc';

module.exports = [
  {
    url: '/vue2-vant/login',
    type: 'post',
    response: (config) => {
      const { loginType } = config.body;

      function checkMobile() {
        const { vcode, mobile } = config.body;
        const isValid = vcode === '1234';
        return {
          code: isValid ? 0 : 1,
          data: isValid
            ? {
                token,
                name: mobile,
                loginType
              }
            : null,
          message: isValid ? '成功' : '验证码错误'
        };
      }

      function checkAccount() {
        const { username, password } = config.body;
        const isValid = username === 'example@123.com' && password === '123456';
        return {
          code: isValid ? 0 : 1,
          data: isValid
            ? {
                token,
                name: username,
                loginType
              }
            : null,
          message: isValid ? '成功' : '账户或密码错误'
        };
      }
      const response = {
        account: checkAccount,
        mobile: checkMobile
      };
      return response[loginType]();
    }
  },
  {
    url: '/vue2-vant/logout',
    type: 'post',
    response: () => {
      return {
        code: 0,
        data: null,
        message: ''
      };
    }
  }
];
